using System;
using System.Drawing;

namespace GDI
{
    public static class RectangleExtentions
    {
        public static Rectangle Union(this Rectangle r1, Rectangle r2)
        {
            var lv_MinX = Math.Min(r1.Location.X, r2.Location.X);
            var lv_MinY = Math.Min(r1.Location.Y, r2.Location.Y);

            var lv_MaxX = Math.Max(r1.Location.X + r1.Width, r2.Location.X + r2.Width);
            var lv_MaxY = Math.Max(r1.Location.Y + r1.Height, r2.Location.Y + r2.Height);

            return new Rectangle(lv_MinX, lv_MinY, lv_MaxX - lv_MinX, lv_MaxY - lv_MinY);
        }

        public static PointF GetCenter(this RectangleF rect)
        {
            return new PointF(rect.Width / 2 + rect.Left, rect.Height / 2 + rect.Top);
        }

        public static Point GetCenter(this Rectangle rect)
        {
            return new Point(rect.Width / 2 + rect.Left, rect.Height / 2 + rect.Top);
        }
    }
}